﻿using adminTemplateApi.Data;
using adminTemplateApi.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace adminTemplateApi.Controllers
{
    public class DynamicPageController : BaseController<DynamicPages, int>
    {
        public DynamicPageController(DBContext context) : base(context)
        {
        }

        protected override int GetIdFromObj(DynamicPages obj)
        {
            return obj.Id;
        }

        [HttpPost]
        public async Task<IActionResult> UpdateConfig([FromBody] DynamicPages obj)
        {
            db.Attach(obj);
            db.Entry(obj).Property(x => x.PageConfig).IsModified = true;
            try
            {
                await db.SaveChangesAsync();
            }
            catch
            {
                throw;
            }

            return NoContent();
        }
    }
}
